﻿using System;
using System.Collections.Generic;
using System.Security.Cryptography;
using System.Text;
using Abp;

namespace Sunlit.Business.Common
{
    public class CaptchaHelper
    {
        private static readonly string[] sourceNumAndLetter = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P,", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
        private static readonly string[] sourceNum = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9"};

        public static string GenerateCaptcha(int length = 6,bool includeLetter=false)
        {
            string code = "";
            var source = includeLetter ? sourceNumAndLetter : sourceNum;
            //获取验证码
            for (int i = 0; i < length; i++)
            {
                code += source[RandomHelper.GetRandom(0, source.Length)];

            }
            
            //返回产生的验证码
            return code.Replace(",", "");
        }
    }
}
